﻿// =================================================================== 
// 项目说明
//====================================================================
// lsc @Copy Right 2019
// 文件： CarGroupBrandRepository.cs
// 项目名称：斑马车务
// 创建时间：2019/11/11
// 负责人：lsc
// ===================================================================
using System;
using System.Text;
using System.Collections.Generic;
using YouWei.Infrastructure.Entity;

namespace YouWei.Infrastructure.Repository
{
	/// <summary>
	/// 仓储层
	/// </summary>	
	public class CarGroupBrandRepository:BaseRepository<CarGroupBrand>
	{		
    
        #region 构造

        public CarGroupBrandRepository() : base(){}

        public CarGroupBrandRepository(string connectionString) : base(connectionString){}

        public CarGroupBrandRepository(DatabaseContext dbContext) : base(dbContext){}

        #endregion

        /// <summary>
        /// 根据群组ID获取所对应的品牌列表
        /// </summary>
        /// <param name="groupId"></param>
        /// <returns></returns>
        public List<CarGroupBrand> GetCarGroupBrandList(List<int> ids)
        {
            if (ids.Count==0)
            {
                return null;
            }
            string gids = string.Join(",", ids.ToArray());
            string sql = @"   SELECT c.*,b.BrandName,s.SerialName 
                              FROM CarGroupBrand c WITH(NOLOCK)
                              LEFT JOIN CarBrand b WITH(NOLOCK) on c.brandid=b.brandid 
                              LEFT JOIN CarSerial s WITH(NOLOCK) ON c.modelid=s.SerialID  AND c.CarGroupID in (" + gids + ")";
            return Query(sql);
        }

        public CarGroupBrand GetCarGroupBrandByModel(int modelId)
        {
            string sql = "SELECT * FROM CarGroupBrand WITH(NOLOCK) WHERE ModelID=" + modelId;
            return FirstOrDefault(sql);
        }
    }
}